local nya__xiaoji = fk.CreateSkill {

  name = "nya__xiaoji",

  tags = {  },

}



nya__xiaoji:addEffect(fk.AfterCardsMove, {
  name = "nya__xiaoji",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(nya__xiaoji.name) then return end
    for _, move in ipairs(data) do
      if move.from==player then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerEquip then
            return true
          end
        end
      end
    end
  end,
  on_trigger = function(self, event, target, player, data)
    local n = 0
    for _, move in ipairs(data) do
      if move.from==player then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerEquip then
            n = n + 1
          end
        end
      end
    end
    self.cancel_cost = false
    for i = 1, n, 1 do
      if self.cancel_cost or not player:hasSkill(nya__xiaoji.name) or player.dead then break end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(player, nya__xiaoji.name) then
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(2, nya__xiaoji.name)
    if not player.dead and not player:hasSkill("nya__play", true) then
      local targets = table.map(table.filter(room.alive_players, function(p)
        return #p:getCardIds("ej") > 0 end), function(p) return p.id end)
      if #targets == 0 then return end
      local to = room:askForChoosePlayers(player, targets, 1, 1, "#nya__xiaoji-choose", nya__xiaoji.name)
      if #to > 0 then
        to = room:getPlayerById(to[1])
        local id = room:askForCardChosen(player, to, "ej", nya__xiaoji.name)
        room:throwCard({id}, nya__xiaoji.name, to, player)
      end
    end
  end,
})

return nya__xiaoji